
import {useEffect, useState} from "react";
import {message} from "antd";
import {addUserSignInUsingPost} from "@/api/userController";


/**
 * 添加用户刷题签到记录钩子
 * @constructor
 */
const useAddUserSignInRecord = () => {

    // 签到状态
    const [loading, setLoading] = useState<boolean>(true)

    // 执行签到
    const doFetch = async () => {
        setLoading(true);
        try {
            await addUserSignInUsingPost({});
            // message.success("签到成功");
        } catch (e) {
            message.error("签到失败，" + (e as Error).message);
        }
        setLoading(false)
    }

    // 保证只调用一次
    useEffect(() => {
        doFetch().then(r => {});
    }, []);

    return {loading}
};

export default useAddUserSignInRecord;
